package regex.test2;


import java.util.Arrays;
/**
 * @author 甘赵辉
 * @date 2023/3/1
 *
 *
 */
public class Main {
    public static void main(String[] args) {
        String input = "aaaaab";
        String input2 ="c";
        String input3 ="abc";
        String regex ="a*b";
        String regex2 ="a+";
        String regex3 ="b+";
        //matches: 匹配
        boolean bo = input.matches(regex);
        System.out.println("aaaaab符合正则表达式a*b吗?:"+bo);
        
        //replaceAll: 替换
        /*
         input中匹配 regex2的 都替换成 input2
         aaaaab中 匹配a+的 , 都匹配成c ,所以变成了cb
         */
        String result = input.replaceAll(regex2, input2);
        System.out.println("aaaaab中 匹配a+的 , 都匹配成c ,所以变成了: "+result);//cb

        //split: 拆分
        String[] split = input3.split(regex3);
        System.out.println(Arrays.toString(split));

        /*
        limit - 结果阈值, 最多拆成几个数组元素
        例如，字符串"boo:and:foo"使用以下参数产生以下结果：
            Regex	Limit	Result
            :	2	{ "boo", "and:foo" }
            :	5	{ "boo", "and", "foo" }
            :	-2	{ "boo", "and", "foo" }
            o	5	{ "b", "", ":and:f", "", "" }
            o	-2	{ "b", "", ":and:f", "", "" }
            o	0	{ "b", "", ":and:f" }
         */
        String[] split2 = input3.split(regex3, 3);
        System.out.println(Arrays.toString(split2));

    }

}
